package warehouse;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnel;
import com.google.common.hash.PrimitiveSink;
import java.util.List;

/**
 *
 * @author Manolescu Razvan
 */
public class BloomFilterColumn {
    private static final int DEFAULT_SIZE = 300;
    private static final double prob = 0.001;
    
    private String columnName;
    private BloomFilter<Integer> bloomFilter;
    
    public BloomFilterColumn(final String columnName, final List<Integer> valueList)
    {
        this(columnName, valueList, DEFAULT_SIZE, prob);
    }
    
    public BloomFilterColumn(final String columnName, final List<Integer> valueList, final int size, final double prob)
    {
       final Funnel<Integer> f = new Funnel<Integer>() {

            @Override
            public void funnel(Integer t, PrimitiveSink ps) {
               ps.putInt(t);
            }
        };

        bloomFilter = BloomFilter.create(f, size, prob);
        
        for(Integer i : valueList){
            bloomFilter.put(i);
        }
    }
    
    public boolean couldContain(final Integer i){
        return bloomFilter.mightContain(i);
    }
    
    public String getColumnName(){
        return columnName;
    }
    
}
